import { NestFactory } from '@nestjs/core';
import { ValidationPipe } from '@nestjs/common';
import { AppModule } from './app.module';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';

async function bootstrap() {
  const app = await NestFactory.create(AppModule, {
    logger: ['log', 'error', 'warn', 'debug', 'verbose'],
    // 开启cors
    cors: true,
  });
  // 设置全局路由前缀
  // app.setGlobalPrefix('api');
  // 设置文档
  const config = new DocumentBuilder()
    .setTitle('swagger文档')
    .setDescription('接口文档')
    .setVersion(process.env.npm_package_version || '')
    .addBearerAuth()
    .build();
  const document = SwaggerModule.createDocument(app, config);
  SwaggerModule.setup('/swagger', app, document);
  // 设置参数验证
  app.useGlobalPipes(
    new ValidationPipe({
      // 不返回错误信息
      // disableErrorMessages: true,
      transform: true,
    }),
  );
  await app.listen(3000);
}
bootstrap();
